/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

/**
 *
 * @author Max
 */
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import org.netbeans.api.visual.graph.layout.GraphLayout;
import org.netbeans.api.visual.graph.layout.GraphLayoutFactory;
import org.netbeans.api.visual.graph.layout.GraphLayoutSupport;
import org.netbeans.api.visual.layout.LayoutFactory;
import org.netbeans.api.visual.layout.SceneLayout;
import controller.TreeSceneErsteller;
import javax.swing.JFrame;
import model.Baum;
import model.Kante;
import model.Knoten;
import org.netbeans.api.visual.graph.GraphScene;

public class BaumAutomat extends javax.swing.JFrame {

    /**
     * Creates new form BaumAutomat
     */
    private static Baum baum;
    private static TreeSceneErsteller scene;
    private Tabellenansicht parentFrame;

    public BaumAutomat(Baum baum) {
        initComponents();
        this.setTitle("Baum automatisch");
        this.baum = baum;
        scene = createScene();
        layoutScene_NetbeansStyle(scene, scene.getWurzel());
        showScene(scene, "Using NetBeans GraphLayout");
        this.setSize(500, 400);
        this.setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
      }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jBTabelle = new javax.swing.JButton();
        jBHilfe = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBackground(new java.awt.Color(153, 255, 153));
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jBTabelle.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jBTabelle.setText("zurück zur Tabellenansicht");
        jBTabelle.setPreferredSize(new java.awt.Dimension(190, 50));
        jBTabelle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTabelleActionPerformed(evt);
            }
        });
        jPanel2.add(jBTabelle);

        jBHilfe.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jBHilfe.setText("Hilfe");
        jBHilfe.setPreferredSize(new java.awt.Dimension(190, 50));
        jBHilfe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBHilfeActionPerformed(evt);
            }
        });
        jPanel2.add(jBHilfe);

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBTabelleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTabelleActionPerformed
        // In die Tabellenansicht wechseln
        //Tabellenansicht tabellenAnsicht = new Tabellenansicht();
        //tabellenAnsicht.getFrame().getContentPane().setBackground(frameStart.getContentPane().getBackground());
        parentFrame.setVisible(true);
        this.dispose();
        
    }//GEN-LAST:event_jBTabelleActionPerformed

    private void jBHilfeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBHilfeActionPerformed
       Hilfefenster hilfe = new Hilfefenster();
    }//GEN-LAST:event_jBHilfeActionPerformed

    /**
     * @param args the command line arguments
     */
    /*  public static void main(String args[]) {
     /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         
     try {
     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
     if ("Nimbus".equals(info.getName())) {
     javax.swing.UIManager.setLookAndFeel(info.getClassName());
     break;
     }
     }
     } catch (ClassNotFoundException ex) {
     java.util.logging.Logger.getLogger(BaumAutomat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     } catch (InstantiationException ex) {
     java.util.logging.Logger.getLogger(BaumAutomat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     } catch (IllegalAccessException ex) {
     java.util.logging.Logger.getLogger(BaumAutomat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     } catch (javax.swing.UnsupportedLookAndFeelException ex) {
     java.util.logging.Logger.getLogger(BaumAutomat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     }
     //</editor-fold>

     /* Create and display the form 
     java.awt.EventQueue.invokeLater(new Runnable() {
     public void run() {
     new BaumAutomat().setVisible(true);
     }
     });
     }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBHilfe;
    private javax.swing.JButton jBTabelle;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

    private void showScene(TreeSceneErsteller scene, String title) {
        JScrollPane panel = new JScrollPane(scene.createView());
        this.add(panel, BorderLayout.CENTER);
    }

    private void layoutScene_NetbeansStyle(
            GraphScene<Knoten, Kante> scene, Knoten root) {
        GraphLayout<Knoten, Kante> graphLayout = GraphLayoutFactory
                .createTreeGraphLayout(100, 100, 50, 50, true);
        GraphLayoutSupport.setTreeGraphLayoutRootNode(graphLayout, root);
        SceneLayout sceneLayout = LayoutFactory.createSceneGraphLayout(scene,
                graphLayout);
        sceneLayout.invokeLayoutImmediately();
    }

    private TreeSceneErsteller createScene() {
        TreeSceneErsteller sceneTemp = new TreeSceneErsteller(baum);
        return sceneTemp;
    }

    /**
     * @param parentFrame the parentFrame to set
     */
    public void setParentFrame(Tabellenansicht parentFrame) {
        this.parentFrame = parentFrame;
    }

}
